

function onchleave(year,m,field,obj) {
  SetLeaveField(year,m,field,obj.value);
  edit_leave();
}

function onchangeleaveyear(year) {
  SetPrefYear(year);edit_leave()
}

function edit_leave() {
  var html="";
  var html_header="";
  var leaveyear=GetPrefYear();
  
  html_header="<h2>Time Budget </h2>";
   
  html_header+="<TABLE><TR><TH>"; 
  html_header+="<fieldset><legend>Year</legend>";
  html_header+="<TABLE><TR><TD>";
  html_header+="<input type=button value='<' onclick='onchangeleaveyear(GetPrefYear()-1)'><input type=text size=4 class='RALIGN' ";
  html_header+="onchange='onchangeleaveyear(this.value)' value='"+leaveyear+"'><input type=button value='>' onclick='onchangeleaveyear(GetPrefYear()-0+1)'>";
  html_header+="</TD></TR></TABLE>";
  html_header+="</fieldset>";
  html_header+="</TH><TH>";
  
  html_header+="<fieldset><legend>Leave Days</legend>";
  html_header+="<TABLE><TR>";
  html_header+="<TH>Imported <input type=text size=3 class='RALIGN' ";
  html_header+=" onchange='SetPrevLeave("+leaveyear+",this.value);edit_leave()'";
  html_header+=" value='"+GetPrevLeave(leaveyear)+"'></TH>";
  html_header+="<TH>Current Year  <input type=text size=3 class='RALIGN' ";
  html_header+=" onchange='SetInitLeave("+leaveyear+",this.value);edit_leave()'";
  html_header+=" value='"+GetInitLeave(leaveyear)+"'></TH> ";
  
  var avail=0;
  if(leaveyear) {
    html+="<TABLE>";
    
    var gross="";
    var leave="";
    var months="";
    var sick="";
    var strike="";
    var home="";
    var dclass="";
    var net="";
    var other="";
    
    
    avail=parseFloat(GetPrevLeave(leaveyear))+parseFloat(GetInitLeave(leaveyear));
    
    var l_iter= new leave_iterator(leaveyear);
    var tgross=0.0,tleave=0.0,tsick=0.0,tstrike=0.0,thome=0.0,tother=0.0,tnet=0.0,tclass=0.0;
    
    while(!l_iter.end()) {
      var local=l_iter.getNet();
      months+="<TH>"+l_iter.getMonthName()+"</TH>";
      gross +="<TD ><input type=text size=3 class='RALIGN GC'  value='"+l_iter.getGross()+"'";
      gross+=" onchange='onchleave("+leaveyear+","+l_iter.getMonth()+",\"gross\",this)'></TD>";
      tgross+=parseFloat(l_iter.getGross()); 
      var mclass="";
      if(l_iter.getLeave()>0) { 
	mclass='RALIGN PL';
      } else {
	mclass='RALIGN';
    }
      leave +="<TD ALIGN=RIGHT><input type=text size=3 class='"+mclass+"' value='"+l_iter.getLeave()+"'";
      leave+=" onchange='onchleave("+leaveyear+","+l_iter.getMonth()+",\"leave\",this)'></TD>";
      tleave+=parseFloat(l_iter.getLeave()); 
      
      if(l_iter.getSick()>0) { 
      mclass='RALIGN PL';
      } else {
	mclass='RALIGN';
      }
      sick +="<TD ALIGN=RIGHT><input type=text size=3 class='"+mclass+"'  value='"+l_iter.getSick()+"'";
      sick+=" onchange='onchleave("+leaveyear+","+l_iter.getMonth()+",\"sick\",this)'></TD>";
      tsick+=parseFloat(l_iter.getSick()); 
      
      if(l_iter.getStrike()>0) { 
	mclass='RALIGN PL';
      } else {
	mclass='RALIGN';
      }
      strike +="<TD ALIGN=RIGHT><input type=text size=3 class='"+mclass+"'  value='"+l_iter.getStrike()+"'";
      strike+=" onchange='onchleave("+leaveyear+","+l_iter.getMonth()+",\"strike\",this)'></TD>";
      tstrike+=parseFloat(l_iter.getStrike()); 
      
      if(l_iter.getHome()>0) { 
	mclass='RALIGN PL';
      } else {
	mclass='RALIGN';
      }
      home+="<TD ALIGN=RIGHT><input type=text size=3 class='"+mclass+"'  value='"+l_iter.getHome()+"'";
      home+=" onchange='onchleave("+leaveyear+","+l_iter.getMonth()+",\"home\",this)'></TD>";
      thome+=parseFloat(l_iter.getHome()); 
      
      dclass+="<TD ALIGN=RIGHT><input type=text size=3 class='"+mclass+"'  value='"+l_iter.getDclas()+"'";
      dclass+=" onchange='onchleave("+leaveyear+","+l_iter.getMonth()+",\"dclas\",this)'></TD>";
      tclass+=parseFloat(l_iter.getDclas()); 
      
      if(l_iter.getOther()>0) { 
	mclass='RALIGN PL';
      } else {
	mclass='RALIGN';
      }
      other+="<TD ALIGN=RIGHT><input type=text size=3 class='"+mclass+"'  value='"+l_iter.getOther()+"'";
      other+=" onchange='onchleave("+leaveyear+","+l_iter.getMonth()+",\"other\",this)'></TD>";
      tother+=parseFloat(l_iter.getOther()); 
      
      net   +="<TD ALIGN=RIGHT><input type=text size=3 class='RALIGN GC' value='"+local+"' readonly></TD>";
      
      //SetLeaveField(leaveyear,l_iter.getMonth(),"net",local);
      avail-=parseFloat(l_iter.getLeave()); 
      tnet+=parseFloat(local);
      l_iter.next();
    }
      
      html+="<TR><TD>     </TD>"+months+"<TH> Total</TH></TR>";
      html+="<TR><TH>Gross</TH>"+gross +"<TD class=VL><input type=text size=3 class='RALIGN GC' readonly  value='"+tgross+"'></TD></TR>";
      html+="<TR><TH>Leave</TH>"+leave +"<TD class=VL><input type=text size=3 class='RALIGN GC' readonly  value='"+tleave+"'></TD></TR>";
      html+="<TR><TH>Sick </TH>"+sick  +"<TD class=VL><input type=text size=3 class='RALIGN GC' readonly  value='"+tsick+"'></TD></TR>";
      html+="<TR><TH>Strike</TH>"+strike +"<TD class=VL><input type=text size=3 class='RALIGN GC' readonly  value='"+tstrike+"'></TD></TR>";
      html+="<TR><TH>Home</TH>" +home +"<TD class=VL><input type=text size=3 class='RALIGN GC' readonly  value='"+thome+"'></TD></TR>";
      html+="<TR><TH>Classification</TH>"+dclass +"<TD class=VL><input type=text size=3 class='RALIGN GC' readonly  value='"+tclass+"'></TD></TR>";
      html+="<TR><TH>Other</TH>" +other +"<TD class=VL><input type=text size=3 class='RALIGN GC' readonly  value='"+tother+"'></TD></TR>";
      html+="<TR><TH colspan=14><HR></TH></TR>";
      html+="<TR><TH>Net  </TH>"+ net  +"<TD class=VL><input type=text size=3 class='RALIGN GC' readonly  value='"+tnet+"'></TD></TR>";
      html+="</TABLE>";    
    
  }
  
  html_header+="<TH>Remaining  <input type=text size=3 class='RALIGN GC' value='"+avail+"' readonly></TH>";
  html_header+="</TR></TABLE>";
  html_header+="</fieldset>";
  html_header+="</TH></TR></TABLE>";
  html_header+="<BR>";
  
  html_display(html_header+html);
}
